package dl.bukkit.myststus.vexshow;

import dl.bukkit.myststus.api.playerdata.ClientSizeData;
import dl.bukkit.myststus.configuration.imp.Config;
import dl.bukkit.myststus.vexshow.sub.Text;
import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.entity.Player;

import java.text.DecimalFormat;

public class Attribute {
    private static final DecimalFormat ROUNDING = new DecimalFormat("0");

    public static final String BACKGROUND_URL = "url";
    public static final String LOCATION_X = "x";
    public static final String LOCATION_Y = "y";
    public static final String PRIORITY_Z = "z";
    public static final String SIZE_WIDTH = "width";
    public static final String SIZE_HEIGHT = "height";
    public static final String SHOW_TIME = "time";
    public static final String CONDITIONS = "conditions";
    public static final String TRIGGERS = "triggers";

    public static int toRounding(Object str) {
        return NumberUtils.toInt(ROUNDING.format(str));
    }

    public static int toValue(Player player, String str, AbstractVexHud vexHud) {
        String s = str
                .replaceAll("\\{" + Config.getInst().getString("Placeholder.ImageWidth") + "}", String.valueOf(vexHud.getW()))
                .replaceAll("\\{" + Config.getInst().getString("Placeholder.ImageHeight") + "}", String.valueOf(vexHud.getH()));
        if (vexHud instanceof Text) {
            Text hud = (Text) vexHud;
            s = s.replaceAll("\\{" + Config.getInst().getString("Placeholder.TextFontLength") + "}", String.valueOf(hud.getLength(player)));
        }
        return toRounding(ClientSizeData.getInst(player).getValue(s));
    }
}
